<?php

namespace app\modules\setting\models;

use Yii;

/**
 * This is the model class for table "rbac_roles_lut".
 *
 * @property int $role_id
 * @property string $role_name
 * @property string|null $description
 * @property string $crt_name
 * @property string $crt_time
 */
class RolesLut extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'rbac_roles_lut';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['crt_time'], 'required'],
            [['crt_time'], 'safe'],
            [['role_name', 'crt_name'], 'string', 'max' => 50],
            [['description'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'role_id' => '角色ID',
            'role_name' => '角色名称',
            'description' => '角色描述',
            'crt_name' => '创建人',
            'crt_time' => '创建时间',
        ];
    }


    /**
     * @return array|\yii\db\ActiveRecord[]
     * @author sally
     * @date   2020-07-06
     */
    static public function getRolesAsList()
    {
        $roles = RolesLut::find()->where(['delete_at' => 0])->all();
        $roles = array_column($roles, 'description', 'role_id');

        return $roles;
    }


    /**
     * @return \yii\db\ActiveQuery
     * @author sally
     * @date   2020-07-06
     */
    public function getRolePermissions()
    {
        return $this->hasMany(RolePermissions::className(), ['role_id' => 'role_id']);
    }
}
